//
//  JMGuidepageViewController.m
//  Sharon
//
//  Created by xiaorui on 14-10-12.
//  Copyright (c) 2014年 xiaorui. All rights reserved.
//

#import "JMGuidepageViewController.h"
#import "AppDelegate.h"


@interface JMGuidepageViewController ()<UIScrollViewDelegate>


@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic,strong) UIPageControl *pageControl;
@end



@implementation JMGuidepageViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationController.navigationBarHidden = YES;
    self.backBtn.hidden =YES;
}
- (void)viewDidLoad{
    [super viewDidLoad];
    [self.view addSubview:self.pageControl];
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, UI_SCREEN_WITH, UI_SCREEN_HEIGHT)];
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.delegate =self;
    self.scrollView.userInteractionEnabled =YES;
    [self.view addSubview:self.scrollView];
    
    NSArray *imageArray =@[@"1.png",@"2.png",@"3.png"];
    for(int i = 0; i<imageArray.count; i ++){
        UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(UI_SCREEN_WITH *i,0, UI_SCREEN_WITH, UI_SCREEN_HEIGHT)];
        imageView.image =[UIImage imageNamed:[imageArray objectAtIndex:i]];
        imageView.userInteractionEnabled = YES;
        [self.scrollView addSubview:imageView];
        if(i == imageArray.count-1){
            UIButton *bnt =[UIButton buttonWithType:UIButtonTypeCustom];
            [bnt addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            bnt.frame = CGRectMake(UI_SCREEN_WITH/2.0 - 14, UI_SCREEN_HEIGHT - 110, 108, 40);
            [bnt setImage:[UIImage imageNamed:@"come_in_main"] forState:UIControlStateNormal];
            [imageView addSubview:bnt];
        }
    }
    self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(UI_SCREEN_WITH/2.0 - 40, UI_SCREEN_HEIGHT - 60, 80, 35)];
    self.pageControl.currentPage = 0;
    self.pageControl.numberOfPages =imageArray.count;
    self.scrollView.contentSize = CGSizeMake(UI_SCREEN_WITH *3, UI_SCREEN_HEIGHT);
}

#pragma mark - Build MYBlurIntroductionView
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int page = (scrollView.contentOffset.x + 30) / 320;
    self.pageControl.currentPage = page;
}
-(void)buttonClick:(UIButton *)sender{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    [app setRootViewController:JM_LoginViewController];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
